package priv.ln.search_sort;

/**
 * ClassName: exer2
 * Package: priv.ln.search_sort
 * Description:冒泡排序
 * int[] arr = new int[]{34,54,3,2,65,7,34,5,76,34,67};
 *
 * @Author 辣辣
 * @Create 2024/6/14 19:02
 * @Version 1.0
 */
public class exer2 {
    public static void main(String[] args) {
        int[] arr = new int[]{34,54,3,2,65,7,34,5,76,34,67};

        for (int i = 0; i < arr.length - 1; i++) {
            //boolean flag = true;//假设数组已经是有序的
            for (int j = 0; j < arr.length - 1 - i; j++) {
                if (arr[j] > arr[j + 1]) {
                    int temp = arr[j];
                    arr[j] = arr[j + 1];
                    arr[j + 1] = temp;

                    //flag = false;//如果元素发生了交换，那么说明数组还没有排好序
                }
            }
            /*
            if (flag) {
                break;
            }

             */
        }
        for (int i = 0; i < arr.length; i++) {
            System.out.print(arr[i] + "\t");
        }
    }
}
